package com.jmkj.service.wechat;

import com.jmkj.service.wechat.repository.WechatTaskRepository;
import com.jmkj.service.wechat.entity.WechatTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.util.Optional;

@EnableJpaRepositories
@SpringBootApplication
@Slf4j
public class ServiceWechatApplication implements CommandLineRunner {
    @Autowired
    private WechatTaskRepository wechatTaskRepository;

	public static void main(String[] args) {
		SpringApplication.run(ServiceWechatApplication.class, args);
	}

    @Override
    public void run(String... args) throws Exception {
//        WechatTask task = new WechatTask();
//        task.setPhoneNum(18969061895L);
//        task.setMessage("hello from 66");
//        task.setTaskCompleted(false);
//        task.setWorkerId(18900000001L);
//        wechatTaskRepository.save(task);
//
//        Optional<WechatTask> optional = wechatTaskRepository.findById(18969061895L);
//        if(optional.isPresent()){
//            log.info("find: {}", optional.get());
//        }

        WechatTask task = wechatTaskRepository.findFirst1ByTaskLaunched(false);
        if(task != null){
            log.info("find task:{}", task);
        }else{
            log.error("can not find task");
        }
    }
}
